﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class UserPlanMonth_UserPlanMonthAdd : System.Web.UI.Page
{
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    UserInfoManager dllUserInfo = new UserInfoManager();
    UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    Authentication dllAuthentication = new Authentication();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        this.gdvMonthPlan.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
        this.gdvMonthPlan.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");


        if (!IsPostBack)
        {
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpDepartment);
            bindDropDownList(this.drpQuarterDate);
            bindDropDownList(this.drpMonthDate);
            BindDefault();
        }

    }


    void BindDefault()
    {
        //默认绑定责任部门文本框
        this.txtMasterDepartment.Text = this.drpDepartment.SelectedItem.Text;
        object[] _value = new object[1];
        _value[0] = objUserInfo.UserName;
        DataTable _departmentManager = dllUserInfo.get(UserInfoManager.field.IsDepartmentManager.ToString(), _value);
        if (_departmentManager.Rows.Count > 0)
        {
            this.txtEvaluatePeople.Value = _departmentManager.Rows[0]["RealName"].ToString();
        }
        this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
        this.txtSlaveDepartment.Value = "独立完成";
    }

    /// <summary>
    /// 创建空DataTable用于绑定GridView
    /// </summary>
    /// <returns></returns>
    DataTable createDataTable()
    {
        DataTable _dataTable = new DataTable();
        _dataTable.Columns.Add("MonthPlanId");
        _dataTable.Columns.Add("MonthPlanSortId" );
        _dataTable.Columns.Add("Source");
        _dataTable.Columns.Add("CompleteTime");
        _dataTable.Columns.Add("WorkItem");
        _dataTable.Columns.Add("MasterDepartment");
        _dataTable.Columns.Add("MasterPeople");
        _dataTable.Columns.Add("SlaveDepartment");
        _dataTable.Columns.Add("SlaveDepartmentDuty");
        _dataTable.Columns.Add("EvaluatePeople");
        _dataTable.Columns.Add("Remart");
        _dataTable.Columns.Add("PlanSendState");
        _dataTable.Columns.Add("PlanStep");
        return _dataTable;
    }

    /// <summary>
    /// 绑定所有的dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {
        //部门绑定
        if (_drp.Equals(this.drpDepartment))
        {
            object[] _value = new object[1];
            Model.UserInfo objUserInfo = new Model.UserInfo();
            _value[0] = objUserInfo.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _value);
            if (_userTable.Rows.Count > 0)
            {
                if (_userTable.Rows[0]["DepartmentId"].ToString().Length > 0)
                {
                    ListItem _li = new ListItem(_userTable.Rows[0]["DepartmentId"].ToString());
                    this.drpDepartment.Items.Add(_li);
                }
                if (_userTable.Rows[0]["PartTimeDepartmentId"].ToString().Length > 0)
                {
                    ListItem _li = new ListItem(_userTable.Rows[0]["PartTimeDepartmentId"].ToString());
                    this.drpDepartment.Items.Add(_li);
                }
                //同时绑定责任人
                this.txtMasterPeople.Value = _userTable.Rows[0]["RealName"].ToString();
            }
        }


        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            //string _year = DateTime.Now.Year.ToString();
            //this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
            //根据系统当前日期查找到对应的年周期
            if (Request.QueryString["Year"] == null)
            {
                DataTable _year = dllQuarterDateManager.getQuarterDate();
                this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year.Rows[0][2].ToString()));
            }
            else
            {
                this.drpYear.SelectedValue = Utility.HttpHelp.getParamsString("Year");
            }

        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                if (Request.QueryString["QuarterDate"] == null)
                {
                    //根据系统当前日期查找到对应的年周期
                    DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                    //如果查到结果（结果只有一条）

                    if (_quartertime.Rows.Count == 1)
                    {
                        this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                        this.drpQuarterDate.DataSource = _quartertime;
                        this.drpQuarterDate.DataTextField = "QuarterName";
                        this.drpQuarterDate.DataValueField = "Quarter_Id";
                    }
                }
                else
                {
                    this.drpQuarterDate.SelectedValue = Utility.HttpHelp.getParamsString("QuarterDate");
                }

                #endregion
                //bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期", "0");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }

        }

        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {
            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {

                this.drpMonthDate.SelectedIndex = -1;
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count == 1)
                {
                    this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                    this.drpMonthDate.DataSource = _monthtime;
                    this.drpMonthDate.DataTextField = "MonthName";
                    this.drpMonthDate.DataValueField = "Month_Id";
                }
                if (Request.QueryString["Id"] != null)
                {
                    this.drpMonthDate.SelectedValue = Utility.HttpHelp.getParamsInt("Id").ToString();
                }
                bindUserMonthPlan();

                #endregion

            }
            else
            {
                ListItem _li = new ListItem("无月周期", "0");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
                bindUserMonthPlan();
            }
        }
    }


    /// <summary>
    /// 绑定空记录表头gridview
    /// </summary>
    void bindUserMonthPlan()
    {
        object[] _value = new object[2];
        _value[0] = objUserInfo.UserName;
        _value[1] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
        DataTable _monthPlan = dllUserPlanMonth.getMonthDateAndSponsor(_value);
        DataView dv = new DataView(_monthPlan);
        dv.Sort = "MonthPlanSortId";
        this.gdvMonthPlan.DataSource = dv;
        this.gdvMonthPlan.DataBind();
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)gdvMonthPlan.Rows[i].Cells[2].FindControl("lbtnSource");
            lbtn.Text = gdvMonthPlan.DataKeys[i]["Source"].ToString();
            wrapByComma(this.gdvMonthPlan, i, 6);
            wrapByComma(this.gdvMonthPlan, i, 7);
            this.gdvMonthPlan.Rows[i].Cells[10].Text = this.gdvMonthPlan.Rows[i].Cells[10].Text.Replace("&", "");
            this.gdvMonthPlan.Rows[i].Cells[10].Text = this.gdvMonthPlan.Rows[i].Cells[10].Text.Replace("nbsp;", "");
            this.gdvMonthPlan.Rows[i].Cells[10].Text = this.gdvMonthPlan.Rows[i].Cells[10].Text.Replace("amp;", "");
            if (gdvMonthPlan.DataKeys[i]["PlanSendState"] != "&nbsp;" && gdvMonthPlan.DataKeys[i]["PlanSendState"] != "")
            {
                if (Convert.ToInt32(gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString()) == 2)
                {
                    gdvMonthPlan.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
            }
        }
        this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);

    }

    /// <summary>
    /// 年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
        bindDropDownList(this.drpMonthDate);
    }

    /// <summary>
    /// 年改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
    }

    /// <summary>
    /// 月改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindUserMonthPlan();
    }

    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (this.ckbAllSelect.Checked == true)
        {
            for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
            {
                CheckBox _chk = ((CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect"));
                _chk.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
            {
                CheckBox _chk = ((CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect"));
                _chk.Checked = false;
            }
        }
    }

    /// <summary>
    /// 保存待发事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        addMonthPlan(0);
        bindUserMonthPlan();

        //清除全选按钮状态
        this.ckbAllSelect.Checked = false;
        #region 善后操作
        //将文本框清空
        this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
        // //默认绑定责任部门文本框
        this.txtMasterDepartment.Text = this.drpDepartment.SelectedItem.Text;
        object[] _value = new object[1];
        _value[0] = objUserInfo.UserName;
        DataTable _departmentManager = dllUserInfo.get(UserInfoManager.field.IsDepartmentManager.ToString(), _value);
        if (_departmentManager.Rows.Count > 0)
        {
            this.txtEvaluatePeople.Value = _departmentManager.Rows[0]["RealName"].ToString();
        }
        bindDropDownList(this.drpDepartment);
        #endregion
    }

    /// <summary>
    /// 立即提交事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        subMitMonthPlan(1);
        bindUserMonthPlan();
        #region 善后操作
        //将文本框清空
        this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
        this.txtCompleteTime.Text = "";
        //this.txtMasterPeople.Value = "";
        this.txtRemark.Text = "";
        this.txtSlaveDepartment.Value = "";
        this.txtSlaveDepartmentDuty.Text = "";
        //this.txtEvaluatePeople.Value = "";
        this.txtWorkItem.Text = "";
        #endregion
        //将文本框清空
        this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
        
        bindDropDownList(this.drpDepartment);
        //清除全选按钮状态
        this.ckbAllSelect.Checked = false;

        BindDefault();
    }

    /// <summary>
    /// 上传事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string _monthId = "";

        int _count = 0;
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _monthId = this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString();
                _count++;
            }
        }
        if (_count == 1)
        {
            //定向到添加年附件路径页面
            string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + _monthId + "&PlanType=6";
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
    }


    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        //得到button所在行        
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        int _rowIndex = iRow.RowIndex;//得到该行的索引        

        //遍历GridView将GridView转为DataTable
        DataTable _monthPlan = createDataTable();
        //获取GridView当前内容导入DataTable

        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            DataRow _drGridView = _monthPlan.NewRow();
            _drGridView["MonthPlanId"] = this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString();
            _drGridView["MonthPlanSortId"] = this.gdvMonthPlan.Rows[i].Cells[1].Text;
            _drGridView["Source"] = this.gdvMonthPlan.Rows[i].Cells[4].Text.ToString();
            _drGridView["CompleteTime"] = this.gdvMonthPlan.Rows[i].Cells[2].Text.ToString();
            _drGridView["WorkItem"] = this.gdvMonthPlan.Rows[i].Cells[3].Text.ToString();
            _drGridView["MasterDepartment"] = this.gdvMonthPlan.Rows[i].Cells[5].Text.ToString();
            _drGridView["MasterPeople"] = this.gdvMonthPlan.Rows[i].Cells[6].Text.ToString();
            _drGridView["SlaveDepartment"] = this.gdvMonthPlan.Rows[i].Cells[7].Text.ToString();
            _drGridView["SlaveDepartmentDuty"] = this.gdvMonthPlan.Rows[i].Cells[8].Text.ToString();
            _drGridView["EvaluatePeople"] = this.gdvMonthPlan.Rows[i].Cells[9].Text.ToString();
            _drGridView["Remart"] = this.gdvMonthPlan.Rows[i].Cells[10].Text.ToString();
            _drGridView["PlanSendState"] = this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString();
            #region 去除特殊符号如&nbsp;
            _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("&", "");
            _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("nbsp;", "");
            _drGridView["MonthPlanId"] = _drGridView["MonthPlanId"].ToString().Replace("&", "");
            _drGridView["MonthPlanId"] = _drGridView["MonthPlanId"].ToString().Replace("nbsp;", "");
            _drGridView["MonthPlanSortId"] = _drGridView["MonthPlanSortId"].ToString().Replace("&", "");
            _drGridView["MonthPlanSortId"] = _drGridView["MonthPlanSortId"].ToString().Replace("nbsp;", "");
            _drGridView["Source"] = _drGridView["Source"].ToString().Replace("&", "");
            _drGridView["Source"] = _drGridView["Source"].ToString().Replace("nbsp;", "");
            _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("&", "");
            _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("nbsp;", "");
            _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("&", "");
            _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("nbsp;", "");

            _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("&", "");
            _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("nbsp;", "");
            _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("&", "");
            _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("nbsp;", "");
            _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("&", "");
            _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("nbsp;", "");
            _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace(",<br>", ",");

            _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("&", "");
            _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("nbsp;", "");
            _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("&", "");
            _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("nbsp;", "");
            _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("&", "");
            _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("nbsp;", "");
            #endregion
            _monthPlan.Rows.Add(_drGridView);
        }

        //计划如果被保存为草稿，也同时删除
        if (this.gdvMonthPlan.DataKeys[_rowIndex]["MonthPlanId"].ToString() != "&nbsp;" && this.gdvMonthPlan.DataKeys[_rowIndex]["MonthPlanId"].ToString().Length > 0)
        {
            if (Convert.ToInt32(this.gdvMonthPlan.DataKeys[_rowIndex]["PlanSendState"].ToString()) != 0)
            {
                Utility.HttpHelp.alert("已提交的计划不可以删除", Page);
                return;
            }
            _monthPlan.Rows[_rowIndex].Delete();
            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.gdvMonthPlan.DataKeys[_rowIndex]["MonthPlanId"].ToString());
            int result = dllUserPlanMonth.del(MonthPlanManager.field.MonthPlanId.ToString(), _value);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("删除月计划未成功，请重试！");
            }
        }
        else
        {
            _monthPlan.Rows[_rowIndex].Delete();
        }
        this.gdvMonthPlan.DataSource = _monthPlan;
        this.gdvMonthPlan.DataBind();


        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            wrapByComma(this.gdvMonthPlan, i, 6);
            wrapByComma(this.gdvMonthPlan, i, 7);
        }
    }


    /// <summary>
    /// 添加事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string _isnull = isNull();
        if (_isnull.Length > 0)
        {
            Utility.HttpHelp.alert(_isnull, Page);
        }
        else
        {
            ListItem _li = this.drpMonthDate.SelectedItem;
            if (_li.Text == "无月周期")
            {
                Utility.HttpHelp.alert("请选择月周期", Page);
                return;
            }
            if (!verifyDate())
            {
                return;
            }
            if (this.txtPlanStep.Text.Trim().Length == 0 || this.txtPlanStep.Text.Trim().Length < 18)
            {
                Utility.HttpHelp.alert("实施步骤不得少于18个字节！", this.Page);
                return;
            }
            if (this.txtSlaveDepartment.Value != "独立完成")
            {
                if (this.txtSlaveDepartmentDuty.Text.Length <= 32)
                {
                    Utility.HttpHelp.alert("配合部门责任字数不得低于32个字符", Page);
                    return;
                }
            }

            DataTable _monthPlan = createDataTable();
            //获取当前gridview的内容导入到datatable
            for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
            {
                DataRow _drGridView = _monthPlan.NewRow();
                _drGridView["MonthPlanId"] = this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString();
                _drGridView["MonthPlanSortId"] =  this.gdvMonthPlan.Rows[i].Cells[1].Text.ToString() ;
                _drGridView["Source"] = ((LinkButton)gdvMonthPlan.Rows[i].Cells[4].FindControl("lbtnSource")).Text;
                _drGridView["CompleteTime"] = this.gdvMonthPlan.Rows[i].Cells[5].Text.ToString();
                _drGridView["WorkItem"] = this.gdvMonthPlan.Rows[i].Cells[2].Text.ToString();
                _drGridView["MasterDepartment"] = this.gdvMonthPlan.Rows[i].Cells[6].Text.ToString();
                _drGridView["MasterPeople"] = this.gdvMonthPlan.Rows[i].Cells[7].Text.ToString();
                _drGridView["SlaveDepartment"] = this.gdvMonthPlan.Rows[i].Cells[8].Text.ToString();
                _drGridView["SlaveDepartmentDuty"] = this.gdvMonthPlan.Rows[i].Cells[9].Text.ToString();
                _drGridView["EvaluatePeople"] = this.gdvMonthPlan.Rows[i].Cells[10].Text.ToString();
                _drGridView["Remart"] = this.gdvMonthPlan.Rows[i].Cells[11].Text.ToString();
                _drGridView["PlanSendState"] = this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString();

                _drGridView["PlanStep"] = this.gdvMonthPlan.Rows[i].Cells[3].Text.ToString();

                _monthPlan.Rows.Add(_drGridView);
                #region 去除特殊符号如&nbsp;
                _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("&", "");
                _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("nbsp;", "");
                _drGridView["MonthPlanSortId"] = _drGridView["MonthPlanSortId"].ToString().Replace("&", "");
                _drGridView["MonthPlanSortId"] = _drGridView["MonthPlanSortId"].ToString().Replace("nbsp;", "");
                _drGridView["Source"] = _drGridView["Source"].ToString().Replace("&", "");
                _drGridView["Source"] = _drGridView["Source"].ToString().Replace("nbsp;", "");
                _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("&", "");
                _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("nbsp;", "");
                _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("&", "");
                _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("nbsp;", "");

                _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("&", "");
                _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("nbsp;", "");
                _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("&", "");
                _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("nbsp;", "");
                _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("&", "");
                _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("nbsp;", "");
                _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace(",<br>", ",");

                _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("&", "");
                _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("nbsp;", "");
                _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("&", "");
                _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("nbsp;", "");
                _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("&", "");
                _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("nbsp;", "");
                _drGridView["PlanStep"] = _drGridView["PlanStep"].ToString().Replace("&", "");
                _drGridView["PlanStep"] = _drGridView["PlanStep"].ToString().Replace("nbsp;", "");
                #endregion
            }
            //获取当前添加的信息内容
            DataRow _drTable = _monthPlan.NewRow();
            _drTable["MonthPlanSortId"] = this.txtMonthPlanSortId.Value.Trim() ;
            _drTable["Source"] = this.lSource.Text;
            _drTable["CompleteTime"] = this.txtCompleteTime.Text.Trim();
            _drTable["WorkItem"] = this.txtWorkItem.Text.Trim();
            _drTable["MasterDepartment"] = this.drpDepartment.SelectedItem.Text;
            _drTable["MasterPeople"] = this.txtMasterPeople.Value.Trim();
            _drTable["SlaveDepartment"] = this.txtSlaveDepartment.Value.Trim();
            _drTable["SlaveDepartmentDuty"] = this.txtSlaveDepartmentDuty.Text.Trim();
            _drTable["EvaluatePeople"] = this.txtEvaluatePeople.Value.Trim();
            _drTable["Remart"] = this.txtRemark.Text;
            _drTable["PlanStep"] = this.txtPlanStep.Text;
            _monthPlan.Rows.Add(_drTable);
            DataView dv = new DataView(_monthPlan);
            dv.Sort = "MonthPlanSortId";
            this.gdvMonthPlan.DataSource = dv;
            this.gdvMonthPlan.DataBind();

            for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
            {
                LinkButton lbtn = (LinkButton)gdvMonthPlan.Rows[i].Cells[4].FindControl("lbtnSource");
                lbtn.Text = gdvMonthPlan.DataKeys[i]["Source"].ToString();
                string _Lengthstart = this.gdvMonthPlan.Rows[i].Cells[5].Text;
                if (_Lengthstart.Length > 9)
                {
                    _Lengthstart = _Lengthstart.Substring(0, 10);//截取字符串，从左边截取10个字符串
                    this.gdvMonthPlan.Rows[i].Cells[5].Text = _Lengthstart;
                }

                //wrapByComma(this.gdvMonthPlan, i, 6);
                wrapByComma(this.gdvMonthPlan, i, 7);



            }

            #region 善后操作
            //将文本框清空
            this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";
            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            this.txtPlanStep.Text = "";
            #endregion
        }
        addMonthPlan1(0);
        bindUserMonthPlan();
        BindDefault();
        bindDropDownList(this.drpDepartment);
    }


    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }

    string isNull()
    {
        #region 验证是否为空
        if (this.txtMonthPlanSortId.Value.Length == 0)
        {
            return "计划排序Id不可以为空！";
        }
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return "完成时间不可以为空！";
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return "负责人不可以为空！";
        }
        if (this.txtWorkItem.Text.Length == 0)
        {
            return "工作项不可以为空！";
        }
        if (this.txtSlaveDepartment.Value.Length == 0)
        {
            return "配合部门不可以为空！";
        }
        if (this.txtSlaveDepartmentDuty.Text.Length < 18 && this.txtSlaveDepartment.Value != "独立完成")
        {
            return "配合部门责任不得少于18个字节！";
        }
        if (this.txtEvaluatePeople.Value.Length == 0)
        {
            return "评估人不可以为空！";
        }
        return "";
        #endregion
    }

    /// <summary>
    /// 时间验证
    /// </summary>
    bool verifyDate()
    {
        #region 必要验证判断
        //判断完成时间是否大于起始时间
        object[] _value = new object[1];
        _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedItem.Value);
        DataTable _monthDate = dllMonthDateManager.get(MonthDateManager.field.Month_Id.ToString(), _value);
        if (_monthDate.Rows.Count > 0)
        {
            DateTime _startTime = Convert.ToDateTime(_monthDate.Rows[0]["MonthStartDay"].ToString());
            DateTime _endTime = Convert.ToDateTime(this.txtCompleteTime.Text.Trim());
            if (!dllAuthentication.IsEndTimeGreaterThanStartTime(_startTime, _endTime))
            {
                Utility.HttpHelp.alert("完成时间需要大于本月起始时间", Page);
                return false;
            }
        }

        return true;
        #endregion
    }

    /// <summary>
    /// 添加月计划方法
    /// </summary>
    /// <param name="state">0草稿 1 提交</param>    
    void addMonthPlan1(int state)
    {
        #region 参数
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        //得到参数 部门名称的DataTable
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }

        //获取登录用户名
        Model.UserInfo objUserInfo = new Model.UserInfo();
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            CheckBox _ckb = (CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            //if (_ckb.Checked == true)
            //{
            _count++;
            if (this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length == 0 || this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString() == "&nbsp;")
            {
                object[] _value = new object[17];
                //完成时间
                _value[0] = Convert.ToDateTime(this.gdvMonthPlan.Rows[i].Cells[5].Text.Trim());
                //工作内容
                _value[1] = this.gdvMonthPlan.Rows[i].Cells[2].Text.Trim();
                //计划实施步骤
                _value[2] = this.gdvMonthPlan.Rows[i].Cells[3].Text.Trim();
                //责任部门
                _value[3] = this.gdvMonthPlan.Rows[i].Cells[6].Text.Trim();
                //责任人
                _value[4] = this.gdvMonthPlan.Rows[i].Cells[7].Text.Trim().Replace("<br>", ",");
                //配合部门
                _value[5] = this.gdvMonthPlan.Rows[i].Cells[8].Text.Trim().Replace("<br>", ",");
                //配合部门责任
                _value[6] = this.gdvMonthPlan.Rows[i].Cells[9].Text.Trim();
                _value[7] = state;//发送状态
                _value[8] = 0;//是否达成共识
                //备注
                _value[9] = this.gdvMonthPlan.Rows[i].Cells[11].Text.Trim(); ;//Remart
                _value[10] = Convert.ToInt32(this.drpMonthDate.SelectedValue);//MonthDate
                _value[11] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());
                _value[12] = objUserInfo.UserName;
                _value[13] = this.gdvMonthPlan.Rows[i].Cells[10].Text.Trim();//评估人
                _value[14] = this.gdvMonthPlan.DataKeys[i]["Source"].ToString();
                _value[15] = 0;
                _value[16] =  this.gdvMonthPlan.Rows[i].Cells[1].Text.Trim() ;
                _valueList.Add(_value);
            }
            //}

        }
        #endregion
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("请选择要保存的计划", Page);
            return;
        }
        if (_valueList.Count == 0)
        {
            Utility.HttpHelp.alert("选择的计划已保存", Page);
        }
        if (_valueList.Count > 0)
        {

            int result = dllUserPlanMonth.addWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("添加月计划未成功，请重试！");
            }
            #region 善后操作
            //将文本框清空
            this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";
            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            #endregion
        }
    }



    /// <summary>
    /// 添加月计划方法
    /// </summary>
    /// <param name="state">0草稿 1 提交</param>    
    void addMonthPlan(int state)
    {
        #region 参数
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        //得到参数 部门名称的DataTable
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }

        //获取登录用户名
        Model.UserInfo objUserInfo = new Model.UserInfo();
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            CheckBox _ckb = (CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (_ckb.Checked == true)
            {
                _count++;
                if (this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length == 0 || this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString() == "&nbsp;")
                {
                    object[] _value = new object[17];
                    //完成时间
                    _value[0] = Convert.ToDateTime(this.gdvMonthPlan.Rows[i].Cells[5].Text.Trim());
                    //工作内容
                    _value[1] = this.gdvMonthPlan.Rows[i].Cells[2].Text.Trim();
                    //计划实施步骤
                    _value[2] = this.gdvMonthPlan.Rows[i].Cells[3].Text.Trim();
                    //责任部门
                    _value[3] = this.gdvMonthPlan.Rows[i].Cells[6].Text.Trim();
                    //责任人
                    _value[4] = this.gdvMonthPlan.Rows[i].Cells[7].Text.Trim().Replace("<br>", ",");
                    //配合部门
                    _value[5] = this.gdvMonthPlan.Rows[i].Cells[8].Text.Trim().Replace("<br>", ",");
                    //配合部门责任
                    _value[6] = this.gdvMonthPlan.Rows[i].Cells[9].Text.Trim();
                    _value[7] = state;//发送状态
                    _value[8] = 0;//是否达成共识
                    //备注
                    _value[9] = this.gdvMonthPlan.Rows[i].Cells[11].Text.Trim(); ;//Remart
                    _value[10] = Convert.ToInt32(this.drpMonthDate.SelectedValue);//MonthDate
                    _value[11] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());
                    _value[12] = objUserInfo.UserName;
                    _value[13] = this.gdvMonthPlan.Rows[i].Cells[10].Text.Trim();//评估人
                    _value[14] = this.gdvMonthPlan.DataKeys[i]["Source"].ToString();
                    _value[15] = 0;
                    _value[16] =  this.gdvMonthPlan.Rows[i].Cells[1].Text.Trim() ;
                    _valueList.Add(_value);
                }
            }

        }
        #endregion
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("请选择要保存的计划", Page);
            return;
        }
        if (_valueList.Count == 0)
        {
            Utility.HttpHelp.alert("选择的计划已保存", Page);
        }
        if (_valueList.Count > 0)
        {

            int result = dllUserPlanMonth.addWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("添加月计划未成功，请重试！");
            }
            #region 善后操作
            //将文本框清空
            this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";
            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            #endregion
        }
    }

    /// <summary>
    /// 提交月计划方法
    /// </summary>
    /// <param name="state">0草稿 1 提交</param>    
    void subMitMonthPlan(int state)
    {
        #region 参数
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        //得到参数 部门名称的DataTable
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }

        //获取登录用户名
        Model.UserInfo objUserInfo = new Model.UserInfo();
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            CheckBox _ckb = (CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (_ckb.Checked == true)
            {
                _count++;
                if (this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length == 0 || this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString() == "&nbsp;")
                {
                    object[] _value = new object[17];
                    //完成时间
                    _value[0] = Convert.ToDateTime(this.gdvMonthPlan.Rows[i].Cells[5].Text.Trim());
                    //工作内容
                    _value[1] = this.gdvMonthPlan.Rows[i].Cells[2].Text.Trim();
                    //计划实施步骤
                    _value[2] = this.gdvMonthPlan.Rows[i].Cells[3].Text.Trim();
                    //责任部门
                    _value[3] = this.gdvMonthPlan.Rows[i].Cells[6].Text.Trim();
                    //责任人
                    _value[4] = this.gdvMonthPlan.Rows[i].Cells[7].Text.Trim().Replace("<br>", ",");
                    //配合部门
                    _value[5] = this.gdvMonthPlan.Rows[i].Cells[8].Text.Trim().Replace("<br>", ",");
                    //配合部门责任
                    _value[6] = this.gdvMonthPlan.Rows[i].Cells[9].Text.Trim();
                    _value[7] = state;//发送状态
                    _value[8] = 0;//是否达成共识
                    //备注
                    _value[9] = this.gdvMonthPlan.Rows[i].Cells[11].Text.Trim(); ;//Remart
                    _value[10] = Convert.ToInt32(this.drpMonthDate.SelectedValue);//MonthDate
                    _value[11] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());
                    _value[12] = objUserInfo.UserName;
                    _value[13] = this.gdvMonthPlan.Rows[i].Cells[10].Text.Trim();//评估人
                    _value[14] = this.gdvMonthPlan.DataKeys[i]["Source"].ToString();
                    _value[15] = 0;
                    _value[16] =  this.gdvMonthPlan.Rows[i].Cells[1].Text.Trim() ;
                    _valueList.Add(_value);
                }
                else
                {
                    if (Convert.ToInt32(this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString()) == 0 || Convert.ToInt32(this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString()) == -1)
                    {
                        string a = this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString();
                        if (Convert.ToInt32(this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString()) == 0 || Convert.ToInt32(this.gdvMonthPlan.DataKeys[i]["PlanSendState"].ToString()) == -1)
                        {
                            editMonthPlan(Convert.ToInt32(this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString()));
                        }
                    }
                }
            }

        }
        #endregion
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("请选择要提交的计划", Page);
            return;
        }
        if (_valueList.Count > 0)
        {
            int result = dllUserPlanMonth.addWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交月计划未成功，请重试！");
            }
            else
            {
                Utility.HttpHelp.alert("提交成功", Page);
            }
            #region 善后操作
            //将文本框清空
            this.txtMonthPlanSortId.Value = Convert.ToString(this.gdvMonthPlan.Rows.Count + 1);
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";
            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            #endregion
        }
    }


    /// <summary>
    /// 修改月计划方法
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-3-7</date>
    void editMonthPlan(int _monthPlanId)
    {
        object[] _value = new object[1];
        _value[0] = _monthPlanId;
        int result = dllUserPlanMonth.edit(MonthPlanManager.field.PlanSendState.ToString(), _value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("提交月计划未成功，请重试！");
        }
    }



    /// <summary>
    /// 查看来源
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSource_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;

        int MonthPlanId = Convert.ToInt32(_gdv.DataKeys[i]["MonthPlanId"].ToString());
        if (MonthPlanId == 0)
        {
            //新增的员工月计划，不需要跳转到指定页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + MonthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=200,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }

    }


    /// <summary>
    /// 修改事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMofify_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _monthId = 0;
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length == 0)
                {
                    Utility.HttpHelp.alert("请保存后再修改！", this.Page);
                    return;
                }
                _monthId = Convert.ToInt32(this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString());
                _count++;
            }
        }
        if (_count == 1)
        {
            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划

            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);

            object[] _value = new object[1];
            _value[0] = _monthId;

            DataTable usermonthplan = dllUserPlanMonth.get(UserPlanMonth.field.MonthPlanId.ToString(), _value);
            if (usermonthplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(usermonthplan.Rows[0]["PlanSendState"]) >= 1)
                {
                    Utility.HttpHelp.alert("计划已提交，不允许修改！", Page);
                    return;
                }
            }

            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _monthId;
                DataTable _iSEvaluatePeople = dllUserPlanMonth.get(UserPlanMonth.field.EvaluatePeople.ToString(), MonthPlanManager.field.MonthPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count > 0)
                {
                    Utility.HttpHelp.alert("评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpMonthDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "ModifyUserPlanMonth.aspx?Id=" + _monthId + "&MonthDate=" + _li.Value + "&url=UserPlanMonthAdd.aspx&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&Year=" + this.drpYear.SelectedValue;
                        ClientScript.RegisterStartupScript(this.GetType(), "windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
    }

    /// <summary>
    /// 员工月计划分解计划添加
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMonthResolve_Click(object sender, EventArgs e)
    {
        //计数器
        int _count = 0;
        //员工月计划id 
        string _MonthPlanId = "";
        string _MonthPlanSortId = "";
        //员工月计划审核流程id
        int _verifyCircuitId = 0;
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        //所在部门
        string _masterDepartment = this.drpDepartment.SelectedItem.Text;
        DataTable _verifyCircuitTable = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_verifyCircuitTable.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }
        else
        {
            _verifyCircuitId = Convert.ToInt32(_verifyCircuitTable.Rows[0]["VerifyCircuitId"].ToString());
        }

        //员工月计划所在周期
        int _MonthDate = Convert.ToInt32(this.drpMonthDate.SelectedValue);
        //发起人
        Model.UserInfo objUserInfo = new Model.UserInfo();
        string _sponsor = objUserInfo.UserName;
        //获得所选员工月计划的id
        for (int i = 0; i < this.gdvMonthPlan.Rows.Count; i++)
        {
            CheckBox _chk = (CheckBox)this.gdvMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (_chk.Checked == true)
            {
                if (this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length > 0)
                {
                    _MonthPlanId = this.gdvMonthPlan.DataKeys[i]["MonthPlanId"].ToString();
                    _MonthPlanSortId = this.gdvMonthPlan.Rows[i].Cells[1].Text;
                }
                _count++;
            }
        }
        if (_MonthPlanId.Length == 0)
        {
            Utility.HttpHelp.alert("计划为草稿状态才可分解", Page);
            return;
        }
        if (_count != 1)
        {
            Utility.HttpHelp.alert("只能选择一个月计划", Page);
            return;
        }
        else
        {
            //定向到添加月分解页面
            string _url = "UserMonthPlanResolveAdd.aspx?_MonthPlanId=" + _MonthPlanId + "&_MonthPlanSortId=" + _MonthPlanSortId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','monthplandetailmodify','height=200,width=902,top=300,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');</script>");

        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个月计划", Page);

        }
    }
}
